local extension = Package("heroes_ev2")
extension.extensionName = "evolution"
--extension.game_modes_whitelist = {"brokenroyal_mode"}

local EV = require "packages/evolution/EV"
local U = require "packages/utility/utility"

Fk:loadTranslationTable{
  ["heroes_ev2"] = "新约角色05-08",
  ["ev"] = "新约",
}

local altera = General(extension, "ev__altera", "ev", 4, 4, General.Female)

local junshenzhijian = fk.CreateTriggerSkill{
  name = "junshenzhijian",
  anim_type = "offensive",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and data.card.trueName == "slash"
    and #AimGroup:getAllTargets(data.tos) == 1
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = EV.getShortRoute(player, room:getPlayerById(data.to))
    for _, p in ipairs(targets) do
      if player.dead then break end
      if not p:isNude() then
        local cid = EV.askForCardChosen(room, player, p, "hes", self.name)
        if cid then
          room:moveCardTo(cid, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true, player.id)
        end
      end
    end
  end,
}

local xingzhiwenzhang = fk.CreateTriggerSkill{
  name = "xingzhiwenzhang",
  anim_type = "offensive",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and player.phase == Player.Play
  end,
  on_cost = function(self, event, target, player, data)
    local unshown = table.filter(player:getCardIds(Player.Hand), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") == 0 end)
    local cards = player.room:askForCard(player, 2, 2, false, self.name, true, tostring(Exppattern{ id = unshown }), "#xingzhiwenzhang")
    if #cards > 0 then
      self.cost_data = cards
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:showCards(self.cost_data)
    if Fk:getCardById(self.cost_data[1]):compareColorWith(Fk:getCardById(self.cost_data[2]), false) then
      room:setPlayerMark(player, "xingzhiwenzhangdamage-turn", Fk:getCardById(self.cost_data[1]):getColorString())
    else
      room:addPlayerMark(player, "xingzhiwenzhangrange-turn", 2)
    end
  end,

  refresh_events = {fk.CardUsing},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and data.card.trueName == "slash"
    and data.card:getColorString() == player:getMark("xingzhiwenzhangdamage-turn")
  end,
  on_refresh = function(self, event, target, player, data)
    data.additionalDamage = (data.additionalDamage or 0) + 1
  end,
}

local xingzhiwenzhang_attackrange = fk.CreateAttackRangeSkill{
  name = "#xingzhiwenzhang_attackrange",
  correct_func = function (self, from, to)
    if from:hasSkill("xingzhiwenzhang") and from:getMark("xingzhiwenzhangrange-turn") > 0 then
      return from:getMark("xingzhiwenzhangrange-turn")
    end
  end,
}
xingzhiwenzhang:addRelatedSkill(xingzhiwenzhang_attackrange)
altera:addSkill(junshenzhijian)
altera:addSkill(xingzhiwenzhang)

Fk:loadTranslationTable{
  ["ev__altera"] = "阿蒂拉",
  ["designer:ev__altera"] = "KINGDOM43",
  ["junshenzhijian"] = "军神之剑",
  [":junshenzhijian"] = "当你使用【杀】指定唯一目标后，你可弃置你到其的短路径上的所有角色的各一张牌。",
  ["xingzhiwenzhang"] = "星之纹章",
  [":xingzhiwenzhang"] = "阶段技（始），你可展示两张手牌，若这些牌的颜色相同/不同，你于本回合内使用此颜色的【杀】造成的伤害+1/攻击范围+2。",
  ["#xingzhiwenzhang"] = "星之纹章：你可展示两张手牌",
}

local Alice = General(extension, "ev__alice", "ev", 3, 3, General.Female)

local shaonvwenle = fk.CreateTriggerSkill{
  name = "shaonvwenle",
  events = {fk.EventPhaseStart, fk.DamageInflicted},
  derived_piles = {"ev__renxing"},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and (player.phase == Player.Play or event == fk.DamageInflicted)
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      local ids = table.filter(player:getCardIds("he"), function (id) return EV.isSingleTarget(Fk:getCardById(id)) end)
      local cards = player.room:askForCard(player, 1, 999, true, self.name, true, tostring(Exppattern{ id = ids }), "#shaonvwenle-put")
      if #cards > 0 then
      self.cost_data = cards
      return true
      end
    else
      --local ids = table.filter(player:getPile("ev__renxing"), function (id) return Fk:getCardById(id).type == Card.TypeEquip end)
      local card = player.room:askForCard(player, 1, 1, false, self.name, true, ".|.|.|ev__renxing|.|equip", "#shaonvwenle-discard", "ev__renxing")
      if #card > 0 then
        self.cost_data = card
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      player:addToPile("ev__renxing", self.cost_data, true, self.name)
    else
      player.room:moveCardTo(self.cost_data, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, "", "", true)
      data.damage = data.damage - 1
    end
  end,
}

local xiaoxiaojunshi = fk.CreateViewAsSkill{
  name = "xiaoxiaojunshi",
  prompt = "你可明置一张与此“人形”类别或花色相同的手牌视为使用之",
  pattern = ".",
  interaction = function()
    local cards = table.filter(Self:getPile("ev__renxing"), function(id) return not table.contains(U.getMark(Self, "@$xiaoxiaojunshi-round"), id) end)
    local all_names = table.map(cards, function(id) return Fk:getCardById(id).name end)
    local invoke_names = {}
    for _, name in ipairs(all_names) do
      if Fk:cloneCard(name).type == Card.TypeBasic or Fk:cloneCard(name):isCommonTrick() then
        table.insertIfNeed(invoke_names, name)
      end
    end
    if #invoke_names > 0 then
      return U.CardNameBox { choices = invoke_names }
    end
  end,
  enabled_at_play = function(self, player)
    return #player:getPile("ev__renxing") > 0
  end,
  enabled_at_response = function(self, player, response)
    return #player:getPile("ev__renxing") > 0 and not response
  end,
  card_filter = function(self, to_select, selected)
    if not self.interaction.data then return end
    local cards = table.filter(Self:getPile("ev__renxing"), function(id)
      return Fk:getCardById(id).name == self.interaction.data and not table.contains(U.getMark(Self, "@$xiaoxiaojunshi-round"), id) end)
    return #selected == 0 and Fk:currentRoom():getCardArea(to_select) == Card.PlayerHand and Fk:getCardById(to_select):getMark("@@shown-inhand") == 0
    and table.find(cards, function(id) return Fk:getCardById(id).suit == Fk:getCardById(to_select).suit or Fk:getCardById(id).type == Fk:getCardById(to_select).type end)
  end,
  before_use = function (self, player, use)
    local room = player.room
    local show = use.card:getMark(self.name)
    if show ~= 0 and table.contains(player:getCardIds("h"), show) then
      EV.OpenCards(room, player, show, self.name)
      local mark = U.getMark(player, "@$xiaoxiaojunshi-round")
      local cards = table.filter(player:getPile("ev__renxing"), function(id)
        return Fk:getCardById(id).name == use.card.name
        and (Fk:getCardById(id).suit == Fk:getCardById(show).suit or Fk:getCardById(id).type == Fk:getCardById(show).type) end)
      if #cards == 1 then
        table.insertIfNeed(mark, cards[1])
      else
        local get = U.askforChooseCardsAndChoice(player, cards, {"OK"}, self.name, "请选择使用的人形")
        if #get > 0 then
          table.insertIfNeed(mark, get[1])
        else
          table.insertIfNeed(mark, cards[1])
        end
      end
      room:setPlayerMark(player, "@$xiaoxiaojunshi-round", mark)
    end
  end,
  view_as = function(self, cards)
    if not self.interaction.data or #cards ~= 1 then return end
    local card = Fk:cloneCard(self.interaction.data)
    card:setMark(self.name, cards[1])
    card.skillName = self.name
    return card
  end,
}

local huiguixuwu = fk.CreateTriggerSkill{
  name = "huiguixuwu",
  events = {fk.EventPhaseStart},
  --derived_piles = {"ev__renxing"},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Finish
    and table.every(player:getCardIds("h"), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") > 0 end)
    and #table.map(table.filter(player.room:getOtherPlayers(player), function(p) return player:inMyAttackRange(p) end), Util.IdMapper) > 0
  end,
  on_cost = function(self, event, target, player, data)
    local n = player:getHandcardNum()
    local cards = player.room:askForCard(player, n, n, false, self.name, true, ".|.|.|ev__renxing", "#huiguixuwu-discard:::"..n, "ev__renxing")
    if #cards > 0 then
      self.cost_data = cards
      return true
    end
    --[[
    local tos, cards = player.room:askForChooseCardsAndPlayers(player, 1, 1, targets, n, n, ".|.|.|ev__renxing", "#huiguixuwu-discard:::"..n, self.name, true, true)
    if #tos > 0 and #cards > 0 then
      self.cost_data = {tos[1], cards}
      return true
    end]]
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = #table.filter(self.cost_data, function (id) return Fk:getCardById(id).type == Card.TypeTrick end)
    player.room:moveCardTo(self.cost_data, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, "", "", true)
    if n > 0 then
      local targets = table.map(table.filter(room:getOtherPlayers(player), function(p) return player:inMyAttackRange(p) end), Util.IdMapper)
      local tos = room:askForChoosePlayers(player, targets, 1, 1, "#huiguixuwu-choose", self.name, true)
      if #tos > 0 then
        room:damage({
          from = player,
          to = player.room:getPlayerById(tos[1]),
          damage = n,
          damageType = fk.NormalDamage,
          skillName = self.name,
        })
      end
    end
  end,
}

Alice:addSkill(shaonvwenle)
Alice:addSkill(xiaoxiaojunshi)
Alice:addSkill(huiguixuwu)

Fk:loadTranslationTable{
  ["ev__alice"] = "爱丽丝",
  ["designer:ev__alice"] = "KINGDOM43",
  ["shaonvwenle"] = "少女文乐",
  [":shaonvwenle"] = "阶段技（始），你可将任意张目标唯一的牌置于角色牌上，称为“人形”。当你受到伤害时，你可弃“人形”中的一张装备牌，令此伤害-1。",
  ["#shaonvwenle-put"] = "你可将任意张目标唯一的牌置于角色牌上",
  ["#shaonvwenle-discard"] = "你可弃“人形”中的一张装备牌，令此伤害-1。",
  ["ev__renxing"] = "人形",
  ["xiaoxiaojunshi"] = "小小军势",
  [":xiaoxiaojunshi"] = "当你需要使用“人形”中的基础牌或即时魔法牌时，若你于本轮内未使用过此“人形”，你可明置一张与之类别或花色相同的手牌，视为使用之。",
  ["@$xiaoxiaojunshi-round"] = "此轮已用",
  ["huiguixuwu"] = "回归虚无",
  [":huiguixuwu"] = "结束阶段，若你的所有手牌均已明置，你可弃等同于手牌数张“人形”，对你攻击范围内的一名角色造成X点伤害（X为这些“人形”中魔法牌的数量）。",
  ["#huiguixuwu-discard"] = "你可弃%arg张“人形",
  ["#huiguixuwu-choose"] = "选择你攻击范围内的一名角色",
}

local Nightingale = General(extension, "ev__nightingale", "ev", 4, 4, General.Female)

local rentilijie = fk.CreateTriggerSkill{
  name = "rentilijie",
  mute = true,
  events = {fk.TargetSpecified, fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self.name) and data.card.type == Card.TypeBasic then
      if event == fk.TargetConfirmed then
        return table.find(player:getCardIds(Player.Hand), function (id) return Fk:getCardById(id).suit == data.card.suit end)
      else
        local to = player.room:getPlayerById(data.to)
        return table.find(to:getCardIds(Player.Hand), function (id) return Fk:getCardById(id).suit == data.card.suit end)
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.TargetConfirmed then
      local ids = table.filter(player:getCardIds(Player.Hand), function (id) return Fk:getCardById(id).suit == data.card.suit end)
      local cards = player.room:askForCard(player, 1, 1, true, self.name, true, tostring(Exppattern{ id = ids }), "#rentilijie-cancel:::"..data.card:toLogString())
      if #cards > 0 then
        self.cost_data = cards[1]
        return true
      end
    else
      return player.room:askForSkillInvoke(player, self.name, nil, "#rentilijie:::"..data.card:toLogString())
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetConfirmed then
      room:moveCardTo(self.cost_data, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true, player.id)
      data.nullifiedTargets = table.map(room.alive_players, Util.IdMapper)
    else
      data.disresponsive = true
    end
  end,
}

local gangzhikanhu = fk.CreateTriggerSkill{
  name = "gangzhikanhu",
  anim_type = "support",
  events = {fk.EnterDying},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryRound) == 0
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#gangzhikanhu::"..target.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local all_choices = {"gangzhikanhu1","gangzhikanhu2"}
    local choices = {}
    if #target:getAvailableEquipSlots(Card.SubtypeWeapon) > 0 and #target:getAvailableEquipSlots(Card.SubtypeArmor) > 0 then
      table.insert(choices, all_choices[1])
    end
    table.insert(choices, all_choices[2])
    local choice = room:askForChoice(target, choices, self.name, "", false, all_choices)
    if choice == all_choices[1] then
      room:abortPlayerArea(target, {"WeaponSlot", "ArmorSlot"})
    else
      room:changeMaxHp(target, -1)
    end
    if not target.dead then
      room:recover({
        who = target,
        num = 1,
        recoverBy = player,
        skillName = self.name
      })
    end
  end,
}

Nightingale:addSkill(rentilijie)
Nightingale:addSkill(gangzhikanhu)

Fk:loadTranslationTable{
  ["ev__nightingale"] = "南丁格尔",
  ["designer:ev__nightingale"] = "KINGDOM43",
  ["rentilijie"] = "人体理解",
  [":rentilijie"] = "当你指定/成为基础牌的一个目标后，若其/你有与此牌花色相同的手牌，你可令其不能对此牌使用牌/弃置一张与此牌花色相同的手牌，令此牌无效。",
  ["#rentilijie"] = "你可令%arg不可被响应",
  ["#rentilijie-cancel"] = "你可弃置一张与%arg花色相同的手牌令此%arg无效",
  ["gangzhikanhu"] = "钢之看护",
  [":gangzhikanhu"] = "轮次技，当一名角色处于濒死状态时，你可令其选择一项：1.废除武器栏与防具栏；2.减少1点体力上限。选择完毕后，其回复1点体力。",
  ["#gangzhikanhu"] = "钢之看护：你可令%dest回复1点体力",
  ["gangzhikanhu1"] = "废除武器栏与防具栏",
  ["gangzhikanhu2"] = "减少1点体力上限",
}

local Suika = General(extension, "ev__suika", "ev", 4, 4, General.Female)
--SPSuika = General(extension, "ev_sp__suika", "ev", 4, 4, General.Female)
local ev__jvshu = fk.CreateActiveSkill{
  name = "ev__jvshu",
  anim_type = "support",
  prompt = "你可弃置至少一张手牌并增加等量点体力上限",
  min_card_num = 1,
  target_num = 0,
  can_use = function(self, player)
    return not player:isKongcheng()
  end,
  card_filter = function(self, to_select, selected)
    return Fk:currentRoom():getCardArea(to_select) == Card.PlayerHand
  end,
  target_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:moveCardTo(effect.cards, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true, player.id)
    room:changeMaxHp(player, #effect.cards)
  end,
}

local ev__jvshu_lose = fk.CreateActiveSkill{
  name = "ev__jvshu_lose",
  anim_type = "offensive",
  card_num = 0,
  target_num = 0,
  interaction = function()
    return UI.Spin {
      from = 1,
      to = Self.maxHp,
    }
  end,
  can_use = Util.FalseFunc,
  on_use = function(self, room, effect)
    if not self.interaction.data then return end
    local player = room:getPlayerById(effect.from)
    local tolose = self.interaction.data
    room:changeMaxHp(player, 0 - tolose, self.name)
    if player.dead then return end
    player:drawCards(tolose, self.name)
  end,
}

local jvshu_trigger = fk.CreateTriggerSkill{
  name = "#jvshu_trigger",
  events = {fk.TargetConfirmed},
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    local _, dat = player.room:askForUseActiveSkill(player, "ev__jvshu_lose", "#jvshu-invoke", true)
    if dat then
      if data.card.trueName == "slash" and table.every(player.room:getOtherPlayers(player), function (p) return p.maxHp > player.maxHp end) then
        EV.nullifiedCard(data, data.card, player)
      end
    end
  end,
}

local ev__huaisui = fk.CreateTriggerSkill{
  name = "ev__huaisui",
  events = {fk.DamageCaused},
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and data.card and data.card.trueName == "slash" then
      return player.room:getBanner("ev__huaisui"..player.id) and player.maxHp > player.room:getBanner("ev__huaisui"..player.id)
    end
  end,
  on_use = function(self, event, target, player, data)
    local n = player.room:getBanner("ev__huaisui"..player.id) - player.maxHp
    player.room:changeMaxHp(player, n, self.name)
    n = math.min(-n, #data.to:getCardIds("he"))
    if n > 0 then
      local cards = EV.askForCardsChosen(player.room, player, data.to, n, n, "hes", self.name)
      if n == #data.to:getCardIds("he") then
        data.damage = data.damage + 1
      end
      player.room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, nil, false, player.id)
    end
  end,

  refresh_events = {fk.EventAcquireSkill},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.name == self.name
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setBanner("ev__huaisui"..player.id, player.maxHp)
  end,
}


Fk:addSkill(ev__jvshu_lose)
ev__jvshu:addRelatedSkill(jvshu_trigger)
Suika:addSkill(ev__jvshu)
Suika:addSkill(ev__huaisui)

Fk:loadTranslationTable{
  ["ev__suika"] = "伊吹萃香",
  ["ev_sp__suika"] = "伊吹萃香",
  ["designer:ev__suika"] = "KINGDOM43",
  ["ev__jvshu"] = "聚疏",
  [":ev__jvshu"] = "出牌阶段，你可弃置至少一张手牌并增加等量点体力上限。当你成为牌的目标后，你可减少至少1点体力上限并摸等量张牌，然后若此牌为【杀】且你为体力上限唯一最小的角色，此牌对你无效。",
  ["#jvshu_trigger"] = "聚疏",
  ["#jvshu-invoke"] = "聚疏：你可减少至少1点体力上限并摸等量张牌",
  ["ev__jvshu_lose"] = "聚疏",
  ["ev__huaisui"] = "坏碎",
  [":ev__huaisui"] = "当你使用【杀】造成伤害时，你可将体力上限减少至初始值，弃置受伤角色的等同于减少值张牌；若你以此法弃置其所有牌，则此伤害+1。",
}

local Enqidu = General(extension, "ev__enqidu", "ev", 4)

local ev__bianrong = fk.CreateTriggerSkill{
  name = "ev__bianrong",
  anim_type = "offensive",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and player.phase == Player.Start
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local num = 7
    local choices = {"1","2","3"}
    local draws = room:askForChoice(player, choices, self.name, "#bianrong_draw", false, {"1","2","3"})
    num = num - tonumber(draws)
    if num > 4 then
      table.removeOne(choices, "1")
      if num > 5 then
        table.removeOne(choices, "2")
      end
    end
    local slashs = room:askForChoice(player, choices, self.name, "#bianrong_slash", false, {"1","2","3"})
    num = num - tonumber(slashs)
    room:setPlayerMark(player, "@ev__bianrong", {tonumber(draws), tonumber(slashs), num})
  end,

  refresh_events = {fk.DrawNCards},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and player:getMark("@ev__bianrong") ~= 0
  end,
  on_refresh = function(self, event, target, player, data)
    data.n = player:getMark("@ev__bianrong")[1]
  end,
}

local bianrong_slash = fk.CreateTargetModSkill{
  name = "#ev__bianrong_targetmod",
  residue_func = function(self, player, skill, scope, card)
    if player:hasSkill("ev__bianrong") and skill.trueName == "slash_skill" and scope == Player.HistoryPhase
    and player:getMark("@ev__bianrong") ~= 0 then
      return player:getMark("@ev__bianrong")[2] - 1
    end
  end,
}

local bianrong_maxcards = fk.CreateMaxCardsSkill{
  name = "#ev__bianrong_maxcards",
  fixed_func = function (self, player)
    if player:hasSkill("ev__bianrong") and player:getMark("@ev__bianrong") ~= 0 then
      return player:getMark("@ev__bianrong")[3]
    end
  end,
}

local ev__tianzhisuo = fk.CreateActiveSkill{
  name = "ev__tianzhisuo",
  anim_type = "support",
  frequency = Skill.Limited,
  card_num = 0,
  target_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected)
    return #selected == 0 and to_select ~= Self.id
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    room:addPlayerMark(player, "@@ev__tianzhisuo")
    room:addPlayerMark(target, "@@ev__tianzhisuo")
    player:setChainState(true)
    target:setChainState(true)
    --room:setBanner("ev__tianzhisuo", {effect.from, effect.tos[1]})
  end,
}

local tianzhisuo_trigger = fk.CreateTriggerSkill{
  name = "#tianzhisuo_trigger",
  mute = true,
  events = {fk.TargetSpecified, fk.TargetConfirmed, fk.TurnStart, fk.BeforeChainStateChange},
  can_trigger = function(self, event, target, player, data)
    if target:getMark("@@ev__tianzhisuo") > 0 and player:hasSkill(self.name) then
      if event == fk.TargetSpecified or event == fk.TargetConfirmed then
        return player ~= target and data.card.trueName == "slash"
      elseif event == fk.TurnStart then
        return player ~= target
      else
        return target.chained
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.TargetSpecified or event == fk.TargetConfirmed then
      return player.room:askForSkillInvoke(player, self.name, nil, "#tianzhisuo-slash:::"..data.card:toLogString())
    elseif event == fk.TurnStart then
      return player.room:askForSkillInvoke(player, self.name, nil, "#tianzhisuo-hands::"..target.id..":"..player:getMaxCards())
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetSpecified or event == fk.TargetConfirmed then
      room:loseHp(player, 1, self.name)
      data.nullifiedTargets = AimGroup:getAllTargets(data.tos)
    elseif event == fk.TurnStart then
      local n = player:getMaxCards() - target:getHandcardNum()
      if n > 0 then
        target:drawCards(n, self.name)
      elseif n < 0 then
        room:askForDiscard(target, -n, -n, false, self.name, false)
      end
    else
      return true
    end
  end,
}

ev__bianrong:addRelatedSkill(bianrong_slash)
ev__bianrong:addRelatedSkill(bianrong_maxcards)
ev__tianzhisuo:addRelatedSkill(tianzhisuo_trigger)
Enqidu:addSkill(ev__bianrong)
Enqidu:addSkill(ev__tianzhisuo)

Fk:loadTranslationTable{
  ["ev__enqidu"] = "恩奇都",
  ["designer:ev__enqidu"] = "KINGDOM43",
  ["ev__bianrong"] = "变容",
  ["@ev__bianrong"] = "变容",
  [":ev__bianrong"] = "锁定技，准备阶段，你将共计7点数值重新分配给以下项（每项初始为0，至多为3）：1.摸牌阶段摸牌数；2.使用【杀】的次数上限；3.手牌上限。",
  ["#bianrong_draw"] = "请分配摸牌阶段摸牌数",
  ["#bianrong_slash"] = "请分配使用【杀】的次数上限",
  ["ev__tianzhisuo"] = "天之锁",
  [":ev__tianzhisuo"] = "限定技，出牌阶段，你可选择一名其他角色，令你与其始终横置。若如此做，其回合开始时，你可令其将手牌摸或弃置至你的手牌上限；且当其指定或成为【杀】的目标后，你可失去1点体力，令此【杀】无效。",
  ["@@ev__tianzhisuo"] = "<font color=\"#B4C424\">天之锁</font>",
  ["#tianzhisuo_trigger"] = "天之锁",
  ["#tianzhisuo-slash"] = "你可失去1点体力令%arg无效",
  ["#tianzhisuo-hands"] = "你可令%dest将手牌摸或弃置至%arg张",
}

local bianhua = General(extension, "ev__bianhua", "ev", 4, 4, General.Female)

local ev__xuezhihuahai = fk.CreateTriggerSkill{
  name = "ev__xuezhihuahai",
  anim_type = "defensive",
  events = {fk.TargetSpecified, fk.TargetConfirmed},
  derived_piles = {"flower"},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and data.card.trueName == "slash" and #player:getPile("flower") < player.hp
  end,
  on_cost = function(self, event, target, player, data)
    local cards = player.room:askForCard(player, 1, 2, true, self.name, true, ".", "#ev__xuezhihuahai")
    if #cards > 0 then
      self.cost_data = cards
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:addToPile("flower", self.cost_data, true, self.name)
    local cards = {}
    if not room:getPlayerById(data.from).dead then
      cards = room:askForDiscard(room:getPlayerById(data.from), 1, 999, true, self.name, true, ".|.|heart,diamond",
      "#huahai-throw:::"..#player:getPile("flower")..":"..data.card:toLogString())
      if #cards < #player:getPile("flower") then
        data.nullifiedTargets = table.map(room.alive_players, Util.IdMapper)
      end
    end
  end,
}

local ev__chituanhua = fk.CreateTriggerSkill{
  name = "ev__chituanhua",
  anim_type = "offensive",
  events = {fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    return target ~= player and player:hasSkill(self.name)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local card = player.room:askForCard(player, 1, 1, false, self.name, true, ".|.|.|flower|.|.", "#ev__chituanhua-invoke", "flower")
    if #card > 0 then
      room:moveCardTo(card, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, "", "", true)
    else
      room:loseHp(player, 1, self.name)
    end
    local n = math.max(player:getLostHp(), 1)
    if #room:askForDiscard(target, n, n, true, self.name, true, ".|.|spade,club", "#chituanhua-throw:::"..n) == 0 then
      room:damage({
        from = player,
        to = target,
        damage = 1,
        damageType = fk.NormalDamage,
        skillName = self.name,
      })
    end
  end,
}

bianhua:addSkill(ev__xuezhihuahai)
bianhua:addSkill(ev__chituanhua)

Fk:loadTranslationTable{
  ["ev__bianhua"] = "彼岸花",
  ["designer:ev__bianhua"] = "次氯酸",
  ["ev__xuezhihuahai"] = "血之花海",
  ["#ev__xuezhihuahai"] = "血之花海：你可将一至两张牌置于角色牌上",
  ["flower"] = "花海",
  [":ev__xuezhihuahai"] = "当你指定或成为【杀】的目标后，若“花海”数小于你的体力值，你可将一至两张牌置于角色牌上，称为“花海”；然后你可令此【杀】的使用者弃置任意张红色牌，若其弃置的牌数小于“花海”数，此【杀】无效。",
  ["#huahai-throw"] = "请弃置任意红色牌，若少于%arg张则%arg2无效",
  ["ev__chituanhua"] = "赤团华",
  [":ev__chituanhua"] = "回合技（始），你可失去1点体力或将一张“花海”置入弃牌堆，令其选择一项：1.弃置X张黑色牌；2.受到你造成的1点伤害（X为你已损失的体力值且至少为1）。",
  ["#ev__chituanhua-invoke"] = "请选择一张“花海”置入弃牌堆，不选则失去1点体力",
  ["#chituanhua-throw"] = "请弃置%arg张黑色牌，否则受到1点伤害",
}

local Fujino = General(extension, "ev__fujino", "ev", 3, 3, General.Female)

local ev__waiqumoyan = fk.CreateTriggerSkill{
  name = "ev__waiqumoyan",
  anim_type = "control",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    --local victim = player.room:getPlayerById(data.to)
    return target == player and player:hasSkill(self.name) and player.id ~= data.to--没人会对自己发动吧？
  end,
  on_cost = function(self, event, target, player, data)
    --local card = player.room:askForCard(player, 1, 1, false, self.name, true, ".", "#ev__waiqumoyan::"..data.to)
    local unshown = table.filter(player:getCardIds(Player.Hand), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") == 0 end)
    local card = player.room:askForCard(player, 1, 1, false, self.name, true, tostring(Exppattern{ id = unshown }), "#ev__waiqumoyan::"..data.to)
    if #card > 0 then
      self.cost_data = card[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(data.to)
    player:showCards({self.cost_data})
    local color = Fk:getCardById(self.cost_data):getColorString()
    room:addPlayerMark(to, "@!waiqu_"..color.."-turn")
    if to:getMark("@!waiqu_red-turn") > 0 and to:getMark("@!waiqu_black-turn") > 0 then
      room:setPlayerMark(to, "@!waiqu_red-turn", 0)
      room:setPlayerMark(to, "@!waiqu_black-turn", 0)
      room:damage({
        from = player,
        to = to,
        damage = 1,
        damageType = fk.NormalDamage,
        skillName = self.name,
      })
    end
  end,
}

local ev__tongjue = fk.CreateTriggerSkill{
  name = "ev__tongjue",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart, fk.Damaged},
  derived_piles = {"pain"},
  can_trigger = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      return target == player and player:hasSkill(self) and player.phase == Player.Start
    else
      return target == player and player:hasSkill(self)
    end
  end,
  on_use = function(self, event, target, player, data)
    local card = player:drawCards(1, self.name)
    player:addToPile("pain", card, false, self.name)
    if #player:getPile("pain") >= player.maxHp then
      player.room:moveCardTo(player:getPile("pain"), Card.PlayerHand, player, fk.ReasonJustMove, self.name, "", false)
    end
  end,
}

Fujino:addSkill(ev__waiqumoyan)
Fujino:addSkill(ev__tongjue)

Fk:loadTranslationTable{
  ["ev__fujino"] = "浅上藤乃",
  ["designer:ev__fujino"] = "KINGDOM43",
  ["ev__waiqumoyan"] = "歪曲魔眼",
  ["#ev__waiqumoyan"] = "歪曲魔眼：你可展示一张手牌令%dest获得一个相同颜色的“歪曲”标记",
  [":ev__waiqumoyan"] = "当你使用牌指定一个目标后，你可展示一张手牌，令其获得一个相同颜色的“歪曲”标记；然后若其有两种颜色的“歪曲”标记，你对其造成1点伤害，其弃所有“歪曲”标记。当前回合结束时，其弃所有“歪曲”标记。",
  ["ev__tongjue"] = "痛觉残留",
  [":ev__tongjue"] = "锁定技，准备阶段或你受到伤害后，你摸一张牌并将之扣置于角色牌上，称为“痛”；然后若“痛”数不小于你的体力上限，你获得所有“痛”。",
  ["pain"] = "痛",
}



local Homura = General(extension, "ev__homura", "ev", 3, 3, General.Female)

local yuanpanshouhu = fk.CreateTriggerSkill{
  name = "yuanpanshouhu",
  anim_type = "drawcard",
  derived_piles = {"yuanpan"},
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      for _, move in ipairs(data) do
        if move.to == player.id and move.toArea == Player.Hand and move.skillName ~= self.name then
          return true
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local gets = {}
    for _, move in ipairs(data) do      
      for _, info in ipairs(move.moveInfo) do
        if move.to == player.id and move.toArea == Player.Hand and move.skillName ~= self.name then
          table.insertIfNeed(gets, info.cardId)
        end
      end
      local cards = room:askForCard(player, 1, 1, true, self.name, true, tostring(Exppattern{ id = gets }), "#yuanpanshouhu")
      if #cards > 0 then
        player:addToPile("yuanpan", cards, true, self.name)
      end
      if #player:getPile("yuanpan") > 0 then
        local card = room:askForCard(player, 1, 1, false, self.name, true, ".|.|.|yuanpan|.|.", "#yuanpanshouhu-get", "yuanpan")
        if #card > 0 then
          room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonJustMove, self.name, "", true)
          room:addCardMark(Fk:getCardById(card[1]), "@@yuanpanshouhu-turn")
        end
      end
    end
  end,
}

local yuanpanshouhu_tar = fk.CreateTargetModSkill{
  name = "#yuanpanshouhu_targetmod",
  residue_func = function(self, player, skill, scope, card)
    if player:hasSkill(self) and card and card:getMark("@@yuanpanshouhu-turn") > 0 then
      return 999
    end
  end,
}

local shikongcaozuo = fk.CreateTriggerSkill{
  name = "shikongcaozuo",
  anim_type = "drawcard",
  events = {fk.TargetSpecified, fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and player:usedSkillTimes(self.name) == 0 then
      return event == fk.TargetSpecified or (player:getMark("@shikongcaozuo") > 0 and player.id ~= data.from)
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.TargetSpecified then
      return #player.room:askForDiscard(player, 1, 1, true, self.name, true, ".", "#shikongcaozuo-throw::"..data.to) > 0
    else
      return #player.room:askForDiscard(player, 1, 1, true, self.name, true, ".", "#shikongcaozuo-discard:::"..player:getMark("@shikongcaozuo")) > 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetSpecified then
      if not room:getPlayerById(data.to):isAllNude() then
        local id = EV.askForCardChosen(room, player, room:getPlayerById(data.to), "hejs", self.name)
        if id > 0 then
          room:moveCardTo(id, Card.PlayerHand, player, fk.ReasonPrey, self.name, "", true, player.id)
        end
      end
    else
      local n = player:getMark("@shikongcaozuo") - player:getHandcardNum()
      if n > 0 then
        player:drawCards(n, self.name)
      end
    end
  end,

  refresh_events = {fk.TurnEnd},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@shikongcaozuo", player:getHandcardNum())
  end,
}

yuanpanshouhu:addRelatedSkill(yuanpanshouhu_tar)
Homura:addSkill(yuanpanshouhu)
Homura:addSkill(shikongcaozuo)

Fk:loadTranslationTable{
  ["ev__homura"] = "晓美焰",
  ["designer:ev__homura"] = "陆丿伯言",
  ["yuanpanshouhu"] = "圆盘守护",
  ["@@yuanpanshouhu-turn"] = "圆盘守护",
  ["#yuanpanshouhu"] = "你可将其中一张牌扣置于角色牌上",
  ["#yuanpanshouhu-get"] = "你可获得角色牌上的一张牌",
  [":yuanpanshouhu"] = "当你不以此法获得牌时，你可将其中至多一张牌扣置于角色牌上，然后你可获得角色牌上的一张牌，你于当前回合内使用此牌无次数限制。",
  ["shikongcaozuo"] = "时空操作",
  ["@shikongcaozuo"] = "时空操作",
  [":shikongcaozuo"] = "回合技，当你使用牌指定一个目标后/成为其他角色使用牌的目标后，你可弃置一张牌，然后获得其区域里的一张牌/将手牌补至与你的上回合结束时相同。",
  ["yuanpan"] = "圆盘",
  ["#shikongcaozuo-throw"] = "时空操作：你可弃置一张牌，获得%dest区域里的一张牌",
  ["#shikongcaozuo-discard"] = "时空操作：你可弃置一张牌，将手牌补至%arg张",
}


local Alter = General(extension, "ev__alter", "ev", 4, 4, General.Female)

local ev__qishi = fk.CreateTriggerSkill{
  name = "ev__qishi",
  anim_type = "drawcard",
  events = {fk.TargetSpecified, fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and (event == fk.TargetConfirmed or data.firstTarget)
    and player:usedSkillTimes(self.name) == 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = #table.map(table.filter(room.alive_players, function(p) return p.role == "lord" or p.role == "loyalist" end), Util.IdMapper)
    if n == 1 then
      player:drawCards(1, self.name)
    elseif n > 0 then
      local ids = room:getNCards(n)
      for i = n, 1, -1 do
        table.insert(room.draw_pile, 1, ids[i])
      end
      --local cids = room:askForArrangeCards(player, self.name, {ids, player:getCardIds("he"), self.name, player.general}, "#ev__qishi-exchange", true)
      local cids = U.askForExchange(player, self.name, player.general, ids, player:getCardIds("he"), "#ev__qishi-exchange", 1, true)
      if #cids > 0 then
        local handcards = table.filter(cids, function (id)
          return table.contains(player:getCardIds("he"), id)
        end)
        local cards = table.filter(cids, function (id)
          return table.contains(room.draw_pile, id)
        end)
        U.swapCardsWithPile(player, handcards, cards, self.name, "Top", true, player.id)
      end
    end
  end,
}

local ev__wuzhu = fk.CreateActiveSkill{
  name = "ev__wuzhu",
  prompt = "#ev__wuzhu",
  frequency = Skill.Limited,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0 and not player:isKongcheng()
  end,
  target_num = 0,
  min_card_num = 1,
  card_filter = function(self, to_select, selected)
    return Fk:getCardById(to_select).color == Card.Red and Fk:currentRoom():getCardArea(to_select) == Card.PlayerHand
    and Fk:getCardById(to_select):getMark("@@shown-inhand") == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    EV.OpenCards(room, player, effect.cards, self.name)
    room:addPlayerMark(player, "@@ev__wuzhu")
  end
}

local wuzhu_prohibit = fk.CreateProhibitSkill{
  name = "#ev__wuzhu_prohibit",
  prohibit_use = function(self, player, card)
    if player:hasSkill("ev__wuzhu") and player:getMark("@@ev__wuzhu") ~= 0 then
      return card.trueName == "slash"
    end
  end,
}

local wuzhu_trigger = fk.CreateTriggerSkill{
  name = "#ev__wuzhu_trigger",
  mute = true,
  events = {fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self.name) and EV.isFriend(player, target) and player:getMark("@@ev__wuzhu") ~= 0 then
      return table.find(player:getCardIds("h"), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") > 0 and Fk:getCardById(id).color == Card.Red end)
    end
  end,
  on_cost = function(self, event, target, player, data)
    local cards = table.filter(player:getCardIds("h"), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") > 0 and Fk:getCardById(id).color == Card.Red end)
    if #cards > 0 then
      local id = player.room:askForCard(player, 1, 1, false, self.name, false, ".|.|.|.|.|.|" .. table.concat(cards, ","), "#ev__wuzhu-discard")
      if #id > 0 then
        self.cost_data = id[1]
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    EV.ConcealCards(player.room, player, self.cost_data, self.name)
    return true
  end,

  refresh_events = {fk.TurnStart},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill("ev__wuzhu") and player:getMark("@@ev__wuzhu") ~= 0
    and #table.filter(player:getCardIds(Player.Hand), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") > 0 end) == 0
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@@ev__wuzhu", 0)
  end
}

ev__wuzhu:addRelatedSkill(wuzhu_trigger)
ev__wuzhu:addRelatedSkill(wuzhu_prohibit)
Alter:addSkill(ev__qishi)
Alter:addSkill(ev__wuzhu)

Fk:loadTranslationTable{
  ["ev__alter"] = "贞德",
  ["designer:ev__alter"] = "小樱",
  ["ev__qishi"] = "启示",
  [":ev__qishi"] = "回合技，当你指定或成为牌的目标后，你可观看牌堆顶的X张牌，然后若X不为/为1，则你可用一张牌交换其中的一张牌/摸一张牌（X为“神谕”阵营角色数）。",
  ["#ev__qishi-exchange"] = "启示：你可用一张牌交换其中的一张牌",
  ["ev__wuzhu"] = "吾主在此",
  ["@@ev__wuzhu"] = "<font color=\"#EC5800\">吾主在此</font>",
  [":ev__wuzhu"] = "限定技，出牌阶段，你可明置至少一张红色手牌，获得以下效果：你不能使用【杀】；当己方角色受到伤害时，你暗置一张红色手牌，防止此伤害；回合开始时，若你没有明置手牌，此效果失效。",
  ["#ev__wuzhu"] = "你可明置至少一张红色手牌",
  ["#ev__wuzhu_prohibit"] = "吾主",
  ["#ev__wuzhu-discard"] = "请暗置一张红色手牌，防止此伤害",
}


local lappland = General(extension, "ev__lappland", "ev", 4, 4, General.Female)

local mental_distroy = fk.CreateTriggerSkill{
  name = "mental_distroy",
  anim_type = "control",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    --local victim = player.room:getPlayerById(data.to)
    return target == player and player:hasSkill(self.name) and player.id ~= data.to--没人会对自己发动吧？
  end,
  on_cost = function(self, event, target, player, data)
    if player.room:askForSkillInvoke(player, self.name, data, "#mental_distroy::"..data.to) then
      self.cost_data = data.to
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data)
    room:addPlayerMark(to, MarkEnum.UncompulsoryInvalidity .. "-turn")
    if player:getHandcardNum() >= to:getHandcardNum() then
      room:setPlayerMark(to, "@@mental_distroy-turn", 1)
    end
  end,
}

local mental_distroy_effect = fk.CreateProhibitSkill{
  name = "#mental_distroy_effect",
  prohibit_use = function(self, player, card)
    return player:getMark("@@mental_distroy-turn") > 0 and card.trueName == "jink"
  end,
}

local ev__langhun = fk.CreateTriggerSkill{
  name = "ev__langhun",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and player:getMark("@ev__langhun") >= 3
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    data.damage = data.damage + 1
  end,

  refresh_events = {fk.DamageFinished},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self.name) and data.from and data.from == player
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:addPlayerMark(player,"@ev__langhun", data.damage)
    if player:getMark("@ev__langhun") >= 6 then
      player.room:setPlayerMark(player, "@ev__langhun", 0)
    end
  end,
}

local langhun_attackrange = fk.CreateAttackRangeSkill{
  name = "#ev__langhun_attackrange",
  correct_func = function (self, from, to)
    if from:hasSkill("ev__langhun") then
      return 2
    end
  end,
}

local langhun_targetmod = fk.CreateTargetModSkill{
  name = "#ev__langhun_targetmod",
  extra_target_func = function(self, player, skill)
    if skill.trueName == "slash_skill" and player:getMark("@ev__langhun") > 0 then
      return 1
    end
  end,
}

mental_distroy:addRelatedSkill(mental_distroy_effect)
ev__langhun:addRelatedSkill(langhun_attackrange)
ev__langhun:addRelatedSkill(langhun_targetmod)
lappland:addSkill(mental_distroy)
lappland:addSkill(ev__langhun)

Fk:loadTranslationTable{
    ["ev__lappland"] = "拉普兰德",
    ["designer:ev__lappland"] = "KINGDOM43",
    ["mental_distroy"] = "精神毁灭",
    ["#mental_distroy_effect"] = "精神毁灭",
    [":mental_distroy"] = "当你使用牌指定一个目标后，你可令其除锁定技与法则技外的技能于当前回合内失效；然后若其手牌数不大于你，其不能于当前回合内使用【闪】。",
    ["#mental_distroy"] = "你可令%dest的非锁定技于当前回合内失效",
    ["@@mental_distroy-turn"] = "精神毁灭",
    ["ev__langhun"] = "狼魂",
    [":ev__langhun"] = "锁定技，若你造成过的伤害数不小于：0，你的攻击范围+2；1，你使用的【杀】可额外选择一个目标；3，你造成的伤害+1；6，你重置计数为0。",
    ["@ev__langhun"] = "狼魂",

    ["$mental_distroy1"] = "让我见识见识你的能耐。",
    ["$mental_distroy2"] = "试着抵抗我吧！",
    ["~ev__lappland"] = "棒极了，这下，我践踏他们的欲望变得更强了！哈哈哈！",
  }


local Risotto = General(extension, "ev__risotto", "ev", 4)

local metalware = fk.CreateActiveSkill{
  name = "metalware",
  anim_type = "control",
  prompt = "你可令你攻击范围内的一名角色展示所有手牌",
  target_num = 1,
  card_num = 0,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected)
    return #selected == 0 and to_select ~= Self.id and not Fk:currentRoom():getPlayerById(to_select):isKongcheng()
    and Self:inMyAttackRange(Fk:currentRoom():getPlayerById(to_select))
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local unshown = table.filter(target:getCardIds(Player.Hand), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") == 0 end)
    if #unshown > 0 then
      target:showCards(unshown)
      if room:askForSkillInvoke(target, self.name, nil, "#metalware-throw") then
        local cards = table.filter(unshown, function(id) return Fk:getCardById(id).color == Card.Black end)
        room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, nil, false, target.id)
      end
    end
    if table.find(target:getCardIds(Player.Hand), function(id) return Fk:getCardById(id).color == Card.Black end) then
      room:damage({
        from = player,
        to = target,
        damage = 1,
        damageType = fk.NormalDamage,
        skillName = self.name,
      })
    else
      room:addPlayerMark(target, "@@metalware")
    end
  end,
}

local metalware_buff = fk.CreateTriggerSkill{
  name = "#metalware-buff",
  events = {fk.DrawNCards},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self.name, true, true) and target:getMark("@@metalware") > 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:setPlayerMark(target, "@@metalware", 0)
    data.n = data.n - 1
  end,
}

metalware:addRelatedSkill(metalware_buff)
Risotto:addSkill(metalware)

Fk:loadTranslationTable{
  ["ev__risotto"] = "里苏特",
  ["designer:ev__risotto"] = "豪曹",
  ["metalware"] = "金属制品",
  [":metalware"] = "阶段技，你可令你攻击范围内的一名角色展示所有手牌，其选择是否弃置其中的黑色牌，然后若其手牌中：没有黑色牌，其下个摸牌阶段少摸一张牌；有黑色牌，你对其造成1点伤害。",
  ["#metalware-throw"] = "你可以弃置手牌中的黑色牌",
  ["@@metalware"] = "金属制品",
}

local lingdong = General(extension, "ev__lingdong", "ev", 4, 4, General.Female)

local ev__wusasi = fk.CreateTriggerSkill{
  name = "ev__wusasi",
  events = {fk.EventPhaseStart},
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target.phase == Player.Discard and target.role_shown and
    (table.contains(U.getMark(player, "wusasi_shown"), target.id) or table.contains(U.getMark(player, "wusasi_slash"), target.id))
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choices = {"ev__wusasi1", "ev__wusasi2"}
    local events = room.logic:getEventsOfScope(GameEvent.Death, 1, function(e)
      local deathStruct = e.data[1]
      return deathStruct.damage and deathStruct.damage.from and deathStruct.damage.from == target
    end, Player.HistoryTurn)
    if #events > 0 or (table.contains(U.getMark(player, "wusasi_shown"), target.id) and table.contains(U.getMark(player, "wusasi_slash"), target.id)) then
      target:drawCards(1, self.name)
      room:addPlayerMark(target, "AddMaxCards-turn")
    else
      local choice = room:askForChoice(target, choices, self.name)
      if choice == "ev__wusasi1" then
        target:drawCards(1, self.name)
      elseif choice == "ev__wusasi2" then
        room:addPlayerMark(target, "AddMaxCards-turn")
      end
    end
  end,

  refresh_events = {fk.CardUsing, "fk.RoleShown"},
  can_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.CardUsing then
      if player:hasSkill(self) and data.card.trueName == "slash" and target.role_shown then
        local slashs = room.logic:getEventsOfScope(GameEvent.UseCard, 999, function(e)
          return e.data[1].card.trueName == "slash" and e.data[1].from == target.id
        end, Player.HistoryGame)
        local events = room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
          return e.data[1].card.trueName == "slash" and EV.isFriend(target, room:getPlayerById(e.data[1].from)) and e.data[1].from ~= target.id
        end, Player.HistoryGame)
        return #slashs == 1 and #events == 0
      end
    else
      if player:hasSkill(self) and data.from == target.id then
        --return #table.filter(room:getOtherPlayers(target), function (p) return EV.isFriend(target, p) end) == 0
        local mark = U.getMark(player, "wusasi_shown")
        return #table.filter(mark, function (p) return EV.isFriend(target, room:getPlayerById(p)) end) == 0
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.CardUsing then
      local mark = U.getMark(player, "wusasi_slash")
      table.insertIfNeed(mark, target.id)
      room:setPlayerMark(player, "wusasi_slash", mark)
    else
      local mark = U.getMark(player, "wusasi_shown")
      table.insertIfNeed(mark, target.id)
      room:setPlayerMark(player, "wusasi_shown", mark)
    end
  end
}

lingdong:addSkill(ev__wusasi)

Fk:loadTranslationTable{
  ["ev__lingdong"] = "凛冬",
  ["designer:ev__lingdong"] = "烈火幽魂",
  ["ev__wusasi"] = "乌萨斯战吼",
  [":ev__wusasi"] = "一名角色的弃牌阶段开始时，若其为其阵营中首名使用【杀】或明置身份牌的角色，你可令其选择一项：1.摸一张牌；2.其手牌上限于此回合内+1。若其满足以上两项条件或于此回合内杀死过角色，其依次执行选项1与2。",
  ["ev__wusasi1"] = "摸一张牌",
  ["ev__wusasi2"] = "手牌上限+1",

  ["$ev__wusasi1"] = "（俄）怕什么！",
  ["$ev__wusasi2"] = "（俄）你们一口气上吧！",
  ["$ev__wusasi3"] = "（俄）力量与荣耀！",
  ["$ev__wusasi4"] = "（俄）胜利与死亡！",
  ["~ev__lingdong"] = "（俄）丢人，你马上给我退出战场！",
}

return extension